package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.SchGrade;
import com.ruoyi.teach.service.ISchGradeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学年Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/teach/grade")
public class SchGradeController extends BaseController
{
    @Autowired
    private ISchGradeService schGradeService;

    /**
     * 查询学年列表
     */
    @PreAuthorize("@ss.hasPermi('teach:grade:list')")
    @GetMapping("/list")
    public TableDataInfo list(SchGrade schGrade)
    {
        startPage();
        List<SchGrade> list = schGradeService.selectSchGradeList(schGrade);
        return getDataTable(list);
    }

    /**
     * 导出学年列表
     */
    @PreAuthorize("@ss.hasPermi('teach:grade:export')")
    @Log(title = "学年", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchGrade schGrade)
    {
        List<SchGrade> list = schGradeService.selectSchGradeList(schGrade);
        ExcelUtil<SchGrade> util = new ExcelUtil<SchGrade>(SchGrade.class);
        util.exportExcel(response, list, "学年数据");
    }

    /**
     * 获取学年详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:grade:query')")
    @GetMapping(value = "/{gId}")
    public AjaxResult getInfo(@PathVariable("gId") Long gId)
    {
        return AjaxResult.success(schGradeService.selectSchGradeByGId(gId));
    }

    /**
     * 新增学年
     */
    @PreAuthorize("@ss.hasPermi('teach:grade:add')")
    @Log(title = "学年", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchGrade schGrade)
    {
        return toAjax(schGradeService.insertSchGrade(schGrade));
    }

    /**
     * 修改学年
     */
    @PreAuthorize("@ss.hasPermi('teach:grade:edit')")
    @Log(title = "学年", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchGrade schGrade)
    {
        return toAjax(schGradeService.updateSchGrade(schGrade));
    }

    /**
     * 删除学年
     */
    @PreAuthorize("@ss.hasPermi('teach:grade:remove')")
    @Log(title = "学年", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gIds}")
    public AjaxResult remove(@PathVariable Long[] gIds)
    {
        return toAjax(schGradeService.deleteSchGradeByGIds(gIds));
    }
}
